package cn.com.yinhex.as.util;

import java.util.ArrayList;

import org.htmlparser.Node;
import org.htmlparser.Parser;
import org.htmlparser.Tag;
import org.htmlparser.filters.TagNameFilter;
import org.htmlparser.util.NodeList;

public class HTMLUtil {
	/**
	 * �õ�����t��
	 * 
	 * @param str
	 * @return
	 */

	public static ArrayList getALink(String html) {
		try {

			Parser parser = Parser.createParser(html, "GBK");
			NodeList list = parser.extractAllNodesThatMatch(new TagNameFilter("a"));
			ArrayList output = new ArrayList();
			for (int i = 0; list != null && i < list.size(); i++) {
				try {
					Node alink = (Node) list.elementAt(i);
					String[] out = new String[2];
					out[0] = ((Tag) alink).getAttribute("href");
					out[1] = alink.getChildren().toHtml().replaceAll("<[^>]*?>", "");
					output.add(out);
				} catch (Exception e) {
					// TODO: handle exception
				}
			}
			return output;
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			return null;
		}
	}
}
